/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package olympicgamesgui;

import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import olympicgameslogic.*;

/**
 *
 * @author Nuno
 */
public class OlympicGamesGui {

   /**
    * @param args the command line arguments
    */
   public static ApplicationData ap = new ApplicationData();
   public ClassLoader cldr = this.getClass().getClassLoader();

   public static void main(String[] args) throws ClassNotFoundException, FileNotFoundException, IOException, InvalidFileException {



      DataImporter dataImporter = new DataImporter();
      ap.setAppUsers(dataImporter.importUsers());
      readData();
      if (ap.getAppUsers() == null) {
	 System.out.println("teste");
	 AppUser fallbackAdminUser = new AppUser("admin", "admin", AppUser.userType.admin);
	 AppUser fallbackEditUser = new AppUser("edit", "edit", AppUser.userType.edit);
	 AppUser fallbackConsultUser = new AppUser("consult", "consult", AppUser.userType.consult);
	 LinkedList<AppUser> appUsers = new LinkedList();
	 appUsers.add(fallbackAdminUser);
	 appUsers.add(fallbackEditUser);
	 appUsers.add(fallbackConsultUser);
	 ap.setAppUsers(appUsers);
      }



      dataImporter.getNationData(ap, new File("C:\\Users/Nuno/Dropbox/Trabalho_LAPR2/Ficheiros CSV/IOC_Codes_v02.csv"));
      dataImporter.getSportsData(ap, new File("C:\\Users/Nuno/Dropbox/Trabalho_LAPR2/Ficheiros CSV/IOC_Sports_v05.csv"));
      dataImporter.getEditionEventsData(ap, new File("C:\\Users/Nuno/Dropbox/Trabalho_LAPR2/Ficheiros CSV/IOC_Sports_OG_2008.csv"));
      dataImporter.getEditionEventsData(ap, new File("C:\\Users/Nuno/Dropbox/Trabalho_LAPR2/Ficheiros CSV/IOC_Sports_OG_1996.csv"));
      dataImporter.getEditionModalityResults(ap, new File("C:\\Users/Nuno/Dropbox/Trabalho_LAPR2/Ficheiros CSV/2008_Swimming_Men.csv"));
      dataImporter.getEditionModalityResults(ap, new File("C:\\Users/Nuno/Dropbox/Trabalho_LAPR2/Ficheiros CSV/2008_Gymnastics_Women.csv"));
      dataImporter.getEditionModalityResults(ap, new File("C:\\Users/Nuno/Dropbox/Trabalho_LAPR2/Ficheiros CSV/2008_Basketball_Women.csv"));
      dataImporter.getEditionModalityResults(ap, new File("C:\\Users/Nuno/Dropbox/Trabalho_LAPR2/Ficheiros CSV/2008_Basketball_Men.csv"));
      dataImporter.getEditionModalityResults(ap, new File("C:\\Users/Nuno/Dropbox/Trabalho_LAPR2/Ficheiros CSV/2008_Athletics_Men.csv"));
      dataImporter.getEditionModalityResults(ap, new File("C:\\Users/Nuno/Dropbox/Trabalho_LAPR2/Ficheiros CSV/1996_Gymnastics_Women.csv"));
      dataImporter.getEditionModalityResults(ap, new File("C:\\Users/Nuno/Dropbox/Trabalho_LAPR2/Ficheiros CSV/1996_Gymnastics_Men.csv"));
      dataImporter.getEditionModalityResults(ap, new File("C:\\Users/Nuno/Dropbox/Trabalho_LAPR2/Ficheiros CSV/1996_Basketball_Women.csv"));
      dataImporter.getEditionModalityResults(ap, new File("C:\\Users/Nuno/Dropbox/Trabalho_LAPR2/Ficheiros CSV/1996_Basketball_Men.csv"));
      dataImporter.getEditionModalityResults(ap, new File("C:\\Users/Nuno/Dropbox/Trabalho_LAPR2/Ficheiros CSV/1996_Athletics_Men.csv"));

//      DataExporter de = new DataExporter();
//      de.exportHtmlNations(ap.getNations());
      
      

      new Login("Login");





   }

   public static void saveData() throws FileNotFoundException, IOException {
      try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("appdata.bin"))) {
	 out.writeObject(ap);
	 out.close();
      }

   }

   public static void readData() {
      try {
	 ObjectInputStream in = null;
	 in = new ObjectInputStream(new FileInputStream("appdata.bin"));
	 ap = (ApplicationData) in.readObject();
	 in.close();
      } catch (IOException | ClassNotFoundException ex) {
	 Logger.getLogger(OlympicGamesGui.class.getName()).log(Level.SEVERE, null, ex);
      }





   }
}
